import pandas as pd
import numpy as np
import plotly.express as px
import seaborn as sns
from matplotlib import pyplot as plt
df = pd.read_csv('results.csv')
df = df.drop(df.columns[0], axis=1)
metadata = pd.read_csv('results_metadata.csv')
metadata.head()
| Unnamed: 0 | anti_martingale | winrate | start_balance | initial_risk | hops | wins_to_skip | risk_multiplier | test_cycles | trades_per_cycle | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | True | 0.55 | 10000.0 | 0.005 | 3 | 0 | 2.0 | 10000 | 100 |
total_trades = metadata['trades_per_cycle'].iloc[0]
mean_winrate = round(np.mean(df['winrate']), 1)
print("mean winrate: " + str(mean_winrate) + "%")
mean winrate: 55.0%
corr = df.corr()
plt.figure(figsize=(11,8))
sns.heatmap(corr, cmap="Greens",annot=True)
plt.show()
# creating seperate dataframes for winning and losing trades
df_profitable = df[df['pnl'] >= 0]
df_losing = df[df['pnl'] < 0]
# Creates subplots
fig, axs = plt.subplots(1, 3, figsize=(15, 5))
# Plots Boxplot for Data 1
axs[0].boxplot(df['chicken_dinners/max_win_streak'])
axs[0].set_title('all chicken dinners')
axs[0].set_xlabel('Sample')
axs[0].set_ylabel('chicken dinners')
# Plots Boxplot for Data 2
axs[1].boxplot(df_profitable['chicken_dinners/max_win_streak'])
axs[1].set_title('profitable cycle chicken dinners')
axs[1].set_xlabel('Sample')
axs[1].set_ylabel('chicken dinners')
# Plots Boxplot for Data 3
axs[2].boxplot(df_losing['chicken_dinners/max_win_streak'])
axs[2].set_title('losing cycle chicken dinners')
axs[2].set_xlabel('Sample')
axs[2].set_ylabel('chicken dinners')
# Adjusts layout
plt.tight_layout()
plt.show()
df['expectancy'] = df['pnl'] / total_trades
df['expectancy%'] = df['pnl%'] / total_trades
mean_excpectancy = round(np.mean(df['expectancy']), 1)
mean_excpectancy_percentage = round(np.mean(df['expectancy%']), 1)
print("expected gain for a single trade: " + str(mean_excpectancy))
print("expected gain% for a single trade: " + str(mean_excpectancy_percentage) + "%")
print("\n")
max_pnl = round(np.max(df['pnl%']), 1)
min_pnl = round(np.min(df['pnl%']), 1)
max_dd = round(np.max(df['max_drawdown%']), 1) * (-1)
mean_pnl = round(np.mean(df['pnl%']), 1)
median_pnl = round(np.median(df['pnl%']), 1)
mean_max_dd = round(np.mean(df['max_drawdown%']), 1) * (-1)
median_max_dd = round(np.median(df['max_drawdown%']), 1) * (-1)
print("biggest gain: " + str(max_pnl) + "%")
print("excpected PnL (average): " + str(mean_pnl) + "%")
print("excpected PnL (median): " + str(median_pnl) + "%")
print("\n")
print("biggest loss: " + str(min_pnl) + "%")
print("biggest drawdown from starting balance: " + str(max_dd) + "%")
print("average max drawdown from starting balance: " + str(mean_max_dd) + "%")
print("median max drawdown from starting balance: " + str(median_max_dd) + "%")
print("\n")
expected gain for a single trade: 9.3 expected gain% for a single trade: 0.1% biggest gain: 59.8% excpected PnL (average): 9.3% excpected PnL (median): 8.8% biggest loss: -22.6% biggest drawdown from starting balance: -24.5% average max drawdown from starting balance: -4.2% median max drawdown from starting balance: -3.2%
# Creates subplots
fig, axs = plt.subplots(1, 3, figsize=(15, 5))
# Plots Boxplot for Data 1
axs[0].boxplot(df['pnl%'])
axs[0].set_title('pnl% distribution')
axs[0].set_xlabel('Sample')
axs[0].set_ylabel('pnl%')
# Plots Boxplot for Data 2
axs[1].boxplot(df['max_drawdown%'])
axs[1].set_title('max drawdown % distribution')
axs[1].set_xlabel('Sample')
axs[1].set_ylabel('Max drawdown%')
# Plots Boxplot for Data 3
axs[2].boxplot(df['winrate'])
axs[2].set_title('winrate % distribution')
axs[2].set_xlabel('Sample')
axs[2].set_ylabel('Winrate%')
# Adjusts layout
plt.tight_layout()
plt.show()
fig = px.scatter(df, x='winrate', y='chicken_dinners/max_win_streak', title='winrate correlation with chicken dinners / max winstreak')
fig.show()
fig = px.scatter(df, x='chicken_dinners/max_win_streak', y='pnl%', title='chicken dinners correlation with pnl%')
fig.show()
fig = px.scatter(df, x='winrate', y='pnl%', title='winrate correlation with pnl%')
fig.show()
fig = px.scatter(df, x='max_drawdown', y='pnl', title='recovery from drawdown')
fig.show()
fig = px.histogram(df, x="max_drawdown%", title="all cycles drawdown")
fig.show()
profitable_ratio = round(len(df_profitable) / len(df), 1) * 100
cd_required = int(np.min(df_profitable['chicken_dinners/max_win_streak']))
profitable_mean_winrate = round(np.mean(df_profitable['winrate']), 1)
profitable_min_winrate = round(np.min(df_profitable['winrate']), 1)
profitable_mean_pnl = round(np.mean(df_profitable['pnl%']), 1)
profitable_median_pnl = round(np.median(df_profitable['pnl%']), 1)
print("proportion of cycles profitable: " + str(profitable_ratio) + "%")
print("min chicken dinners required for profitability: " + str(cd_required))
print("min winrate for profitability: " + str(profitable_min_winrate) + "%")
print("average winrate among profitable cycles: " + str(profitable_mean_winrate) + "%")
print("excpected gain if profitable (average): " + str(profitable_mean_pnl) + "%")
print("excpected gain if profitable (median): " + str(profitable_median_pnl) + "%")
print("\n")
proportion of cycles profitable: 80.0% min chicken dinners required for profitability: 6 min winrate for profitability: 45.0% average winrate among profitable cycles: 56.6% excpected gain if profitable (average): 13.3% excpected gain if profitable (median): 11.5%
# Creates subplots
fig, axs = plt.subplots(1, 3, figsize=(15, 5))
# Plots Boxplot for Data 1
axs[0].boxplot(df_profitable['pnl%'])
axs[0].set_title('pnl% distribution')
axs[0].set_xlabel('Sample')
axs[0].set_ylabel('pnl%')
# Plots Boxplot for Data 2
axs[1].boxplot(df_profitable['max_drawdown%'])
axs[1].set_title('max drawdown % distribution')
axs[1].set_xlabel('Sample')
axs[1].set_ylabel('Max drawdown%')
# Plots Boxplot for Data 3
axs[2].boxplot(df_profitable['winrate'])
axs[2].set_title('winrate % distribution')
axs[2].set_xlabel('Sample')
axs[2].set_ylabel('Winrate%')
# Adjusts layout
plt.tight_layout()
plt.show()
fig = px.histogram(df_profitable, x="max_drawdown%", title="profitable accounts drawdown")
fig.show()
dfdd5 = df[df['max_drawdown%'] > 5]
df_profitabledd5 = df_profitable[df_profitable['max_drawdown%'] > 5]
if len(dfdd5) > 0:
print('chance of being profitable after more than 5% drawdown: ' + str(len(df_profitabledd5) / len(dfdd5)))
dfdd10 = df[df['max_drawdown%'] > 10]
df_profitabledd10 = df_profitable[df_profitable['max_drawdown%'] > 10]
if len(dfdd10) > 0:
print('chance of being profitable after more than 10% drawdown: ' + str(len(df_profitabledd10) / len(dfdd10)))
dfdd20 = df[df['max_drawdown%'] > 20]
df_profitabledd20 = df_profitable[df_profitable['max_drawdown%'] > 20]
if len(dfdd20) > 0:
print('chance of being profitable after more than 20% drawdown: ' + str(len(df_profitabledd20) / len(dfdd20)))
dfdd30 = df[df['max_drawdown%'] > 30]
df_profitabledd30 = df_profitable[df_profitable['max_drawdown%'] > 30]
if len(dfdd30) > 0:
print('chance of being profitable after more than 30% drawdown: ' + str(len(df_profitabledd30) / len(dfdd30)))
dfdd40 = df[df['max_drawdown%'] > 40]
df_profitabledd40 = df_profitable[df_profitable['max_drawdown%'] > 40]
if len(dfdd40) > 0:
print('chance of being profitable after more than 40% drawdown: ' + str(len(df_profitabledd40) / len(dfdd40)))
dfdd50 = df[df['max_drawdown%'] > 50]
df_profitabledd50 = df_profitable[df_profitable['max_drawdown%'] > 50]
if len(dfdd50) > 0:
print('chance of being profitable after more than 50% drawdown: ' + str(len(df_profitabledd50) / len(dfdd50)))
dfdd60 = df[df['max_drawdown%'] > 60]
df_profitabledd60 = df_profitable[df_profitable['max_drawdown%'] > 60]
if len(dfdd60) > 0:
print('chance of being profitable after more than 60% drawdown: ' + str(len(df_profitabledd60) / len(dfdd60)))
dfdd70 = df[df['max_drawdown%'] > 70]
df_profitabledd70 = df_profitable[df_profitable['max_drawdown%'] > 70]
if len(dfdd70) > 0:
print('chance of being profitable after more than 70% drawdown: ' + str(len(df_profitabledd70) / len(dfdd70)))
dfdd80 = df[df['max_drawdown%'] > 80]
df_profitabledd80 = df_profitable[df_profitable['max_drawdown%'] > 80]
if len(dfdd80) > 0:
print('chance of being profitable after more than 80% drawdown: ' + str(len(df_profitabledd80) / len(dfdd80)))
chance of being profitable after more than 5% drawdown: 0.47013546798029554 chance of being profitable after more than 10% drawdown: 0.13309352517985612 chance of being profitable after more than 20% drawdown: 0.0
losing_mean_pnl = round(np.mean(df_losing['pnl%']), 1)
losing_median_pnl = round(np.median(df_losing['pnl%']), 1)
losing_mean_winrate = round(np.mean(df_losing['winrate']), 1)
losing_max_winrate = round(np.max(df_losing['winrate']), 1)
print("excpected PnL (average) for a losing cycle: " + str(losing_mean_pnl) + "%")
print("excpected PnL (median) for a losing cycle: " + str(losing_median_pnl) + "%")
print("max winrate among losing cycles: " + str(losing_max_winrate) + "%")
print("average winrate among losing cycles: " + str(losing_mean_winrate) + "%")
excpected PnL (average) for a losing cycle: -5.5% excpected PnL (median) for a losing cycle: -4.8% max winrate among losing cycles: 58.0% average winrate among losing cycles: 49.0%
# Creates subplots
fig, axs = plt.subplots(1, 3, figsize=(15, 5))
# Plots Boxplot for Data 1
axs[0].boxplot(df_losing['pnl%'])
axs[0].set_title('pnl% distribution')
axs[0].set_xlabel('Sample')
axs[0].set_ylabel('pnl%')
# Plots Boxplot for Data 2
axs[1].boxplot(df_losing['max_drawdown%'])
axs[1].set_title('max drawdown % distribution')
axs[1].set_xlabel('Sample')
axs[1].set_ylabel('Max drawdown%')
# Plots Boxplot for Data 3
axs[2].boxplot(df_losing['winrate'])
axs[2].set_title('winrate % distribution')
axs[2].set_xlabel('Sample')
axs[2].set_ylabel('Winrate%')
# Adjusts layout
plt.tight_layout()
plt.show()
fig = px.histogram(df_losing, x="max_drawdown%", title="losing accounts drawdown")
fig.show()
df_losing5 = df_losing[df_losing['pnl%'] < -5]
print('chance of losing more than 5%: ' + str(len(df_losing5) / len(df)))
df_losing10 = df_losing[df_losing['pnl%'] < -10]
print('chance of losing more than 10%: ' + str(len(df_losing10) / len(df)))
df_losing20 = df_losing[df_losing['pnl%'] < -20]
print('chance of losing more than 20%: ' + str(len(df_losing20) / len(df)))
df_losing30 = df_losing[df_losing['pnl%'] < -30]
print('chance of losing more than 30%: ' + str(len(df_losing30) / len(df)))
df_losing40 = df_losing[df_losing['pnl%'] < -40]
print('chance of losing more than 40%: ' + str(len(df_losing40) / len(df)))
df_losing50 = df_losing[df_losing['pnl%'] < -50]
print('chance of losing more than 50%: ' + str(len(df_losing50) / len(df)))
chance of losing more than 5%: 0.0973 chance of losing more than 10%: 0.0312 chance of losing more than 20%: 0.0005 chance of losing more than 30%: 0.0 chance of losing more than 40%: 0.0 chance of losing more than 50%: 0.0